package com.ruoyi.web.controller.productReturn;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.productReturn.domain.PointsReturnRequest;
import com.ruoyi.productReturn.service.IPointsReturnRequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 积分商品退货管理Controller
 * 
 * @author amy
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/productReturn/productReturn")
@Tag(name = "【积分商品退货管理】管理")
public class PointsReturnRequestController extends BaseController
{
    @Autowired
    private IPointsReturnRequestService pointsReturnRequestService;

    /**
     * 查询积分商品退货列表
     */
    @Operation(summary = "查询积分商品退货列表")
    @PreAuthorize("@ss.hasPermi('productReturn:productReturn:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsReturnRequest pointsReturnRequest)
    {
        startPage();
        List<PointsReturnRequest> list = pointsReturnRequestService.selectAllPointsReturnRequestList(pointsReturnRequest);
        return getDataTable(list);
    }

    /**
     * 查询用户商品退货列表
     */
    @Operation(summary = "查询用户商品退货列表")
    @GetMapping("/userList")
    public TableDataInfo userList(PointsReturnRequest pointsReturnRequest)
    {
        startPage();
        List<PointsReturnRequest> list = pointsReturnRequestService.selectUserPointsReturnRequestList(pointsReturnRequest);
        return getDataTable(list);
    }

    /**
     * 导出积分商品退货管理列表
     */
    @Operation(summary = "导出积分商品退货管理列表")
    @PreAuthorize("@ss.hasPermi('productReturn:productReturn:export')")
    @Log(title = "积分商品退货管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsReturnRequest pointsReturnRequest)
    {
        List<PointsReturnRequest> list = pointsReturnRequestService.selectAllPointsReturnRequestList(pointsReturnRequest);
        ExcelUtil<PointsReturnRequest> util = new ExcelUtil<PointsReturnRequest>(PointsReturnRequest.class);
        util.exportExcel(response, list, "积分商品退货管理数据");
    }

    /**
     * 获取积分商品退货管理详细信息
     */
    @Operation(summary = "获取积分商品退货管理详细信息")
    @PreAuthorize("@ss.hasPermi('productReturn:productReturn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsReturnRequestService.selectPointsReturnRequestById(id));
    }

    /**
     * 新增积分商品退货管理
     */
    @Operation(summary = "新增积分商品退货管理")
    @Log(title = "积分商品退货管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsReturnRequest pointsReturnRequest)
    {
        return toAjax(pointsReturnRequestService.insertPointsReturnRequest(pointsReturnRequest));
    }

    /**
     * 修改积分商品退货管理
     */
    @Operation(summary = "修改积分商品退货管理")
    @PreAuthorize("@ss.hasPermi('productReturn:productReturn:edit')")
    @Log(title = "积分商品退货管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsReturnRequest pointsReturnRequest)
    {
        return pointsReturnRequestService.updatePointsReturnRequest(pointsReturnRequest);
    }

    /**
     * 删除积分商品退货管理
     */
    @Operation(summary = "删除积分商品退货管理")
    @PreAuthorize("@ss.hasPermi('productReturn:productReturn:remove')")
    @Log(title = "积分商品退货管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(pointsReturnRequestService.deletePointsReturnRequestByIds(ids));
    }
}
